<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/%E7%97%95%E8%BF%B9.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/%E7%97%95%E8%BF%B9.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.lug.ustc.edu.cn/css?family=Lato:300,300italic,400,400italic,700,700italic|Gabriola:300,300italic,400,400italic,700,700italic|Arial:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"tian_yu_ting.gitee.io","root":"/","scheme":"Gemini","version":"7.7.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="1、请求过程">
<meta property="og:type" content="article">
<meta property="og:title" content="网页请求">
<meta property="og:url" content="https://tian_yu_ting.gitee.io/Spider/Spider_id_16.html">
<meta property="og:site_name" content="Yu ting&#39;s blog">
<meta property="og:description" content="1、请求过程">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-05-29T11:51:43.009Z">
<meta property="article:modified_time" content="2020-05-17T07:31:26.538Z">
<meta property="article:author" content="Yu ting">
<meta property="article:tag" content="Spider">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://tian_yu_ting.gitee.io/Spider/Spider_id_16.html">

<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true
  };
</script>

  
  
    <script src="/js/cursor/love.min.js"></script>
  

  <title>网页请求 | Yu ting's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

  <script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
  </script>

   <!-- 不知道是什么玩意 -->
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
<link rel="alternate" href="/atom.xml" title="Yu ting's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" style="background-image:url(/images/14.jpg);background-repeat:no-repeat;background-attachment: fixed;">


  <div class="container use-motion">
    <!-- 网页上方的黑色长线 -->
    <div class="headband"></div>
    
    <!-- 在首页添加github图标 -->
<!--     <a href="https://github.com/h4055874" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub">
      <svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
      </svg>
    </a>
      <style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style> -->
    <!--  -->

    <!-- -->

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Yu ting's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">I only for you!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">66</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类<span class="badge">16</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">171</span></a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
        <!--
        <input id="switch_default" type="checkbox" class="switch_default">
        <label for="switch_default" class="toggleBtn"></label>
        -->
      </li>
  </ul>

<style>
    /*input css begin*/
*{
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}
/* input[type="checkbox"],input[type="radio"]{
    display: none;
    width: 0;
    height: 0;
    visibility: hidden;
} */
input[type="checkbox"]:checked + label:after{
    transition: all 0.3s ease-in;
}
input[type="checkbox"]:not(:checked) + label:after {
    transition: all 0.3s ease-out;
}
input[type="checkbox"]:checked + label,
input[type="checkbox"]:not(:checked) + label{
    transition: all 0.3s ease-in-out;
}
input[type="checkbox"]:checked + label:before,input[type="checkbox"]:checked + label i:before,input[type="checkbox"]:not(:checked) + label i:before,
input[type="checkbox"]:checked + label i:after,input[type="checkbox"]:not(:checked) + label i:after,input[type="checkbox"]:not(:checked) + label:before{
    transition: all 0.3s ease-in-out;
}
input[type="radio"]:checked + label:after,
input[type="radio"]:not(:checked) + label:after {
    transition: all 0.3s ease-in-out;
}
.switch_default[type="checkbox"]{
    display: none;
}
.switch_default + label{
     background-color: #e6e6e6;
     border-radius:7px;
     cursor: pointer;
     display: inline-block;
     height: 14px;
     position: relative;
     box-shadow: 0.2px 0.2px 1px 0.5px rgb(180,180,180);
     width: 30px;
 }
.switch_default + label:after{
    background-color: #fff;
    border-radius: 50%;
    content: "";
    height: 12px;
    left: 1px;
    position: absolute;
    top: .5px;
    width: 12px;
    box-shadow: 0.2px 0.2px 1px 0.5px rgb(180,180,180);
}
.switch_default:checked + label{
    background-color: #1ABC9C;
    box-shadow:none;
}
.switch_default:checked + label:after{
    left: 17px;
}
</style>
</nav>
  <div class="site-search">
    <div class="search-pop-overlay">
  <div class="popup search-popup">
      <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

  </div>
</div>

  </div>
</div>
    </header>

    <!-- -->
    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
    <!--sm -->
      <div class="main-inner">
        <div class="content-wrap">
          


          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://tian_yu_ting.gitee.io/Spider/Spider_id_16.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Yu ting">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Yu ting's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          网页请求
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-05-29 19:51:43" itemprop="dateCreated datePublished" datetime="2020-05-29T19:51:43+08:00">2020-05-29</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-17 15:31:26" itemprop="dateModified" datetime="2020-05-17T15:31:26+08:00">2020-05-17</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Python/" itemprop="url" rel="index"><span itemprop="name">Python</span></a>
                </span>
            </span>

          
            <span id="/Spider/Spider_id_16.html" class="post-meta-item leancloud_visitors" data-flag-title="网页请求" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/Spider/Spider_id_16.html#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/Spider/Spider_id_16.html" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>5.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="1、请求过程"><a href="#1、请求过程" class="headerlink" title="1、请求过程"></a>1、请求过程</h2><a id="more"></a>

<h2 id="1、1-URL介绍"><a href="#1、1-URL介绍" class="headerlink" title="1、1  URL介绍"></a>1、1  URL介绍</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">URL作用：用于定位服务器资源</span><br><span class="line">    <span class="comment"># 结构：</span></span><br><span class="line">        <span class="number">1</span>)协议：Protocol</span><br><span class="line">        <span class="number">2</span>)域名：domain</span><br><span class="line">        <span class="number">3</span>)端口：port</span><br></pre></td></tr></table></figure>

<h2 id="1、2-HTTP请求过程"><a href="#1、2-HTTP请求过程" class="headerlink" title="1、2  HTTP请求过程"></a>1、2  HTTP请求过程</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 请求过程：</span></span><br><span class="line">	客户端通常指web浏览器或APP向服务器发起请求，服务器接收到请求后进行处理，并向客户端发起响应</span><br></pre></td></tr></table></figure>

<h2 id="1、3-请求四部分"><a href="#1、3-请求四部分" class="headerlink" title="1、3  请求四部分"></a>1、3  请求四部分</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 由客户端向服务器发出的，可以分为四部分内容：</span></span><br><span class="line">        <span class="number">1</span>)请求方法(Request Method)</span><br><span class="line">        <span class="number">2</span>)请求网址(Request URL)</span><br><span class="line">        <span class="number">3</span>)请求头(Request Headers)</span><br><span class="line">        <span class="number">4</span>)请求体(Request Body)</span><br></pre></td></tr></table></figure>

<h2 id="1、4-请求的八种方法"><a href="#1、4-请求的八种方法" class="headerlink" title="1、4  请求的八种方法"></a>1、4  请求的八种方法</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 请求常见的八种方法：</span></span><br><span class="line">        <span class="number">1</span>)GET：请求页面,并返回页面内容</span><br><span class="line">        <span class="number">2</span>)POST：用于提交表单数据或上传文件，数据包含在请求体中</span><br><span class="line">        <span class="number">3</span>)PUT：从客户端向服务器传送的数据取代指定文档中的内容，就是所谓的更新指定内容</span><br><span class="line">        <span class="number">4</span>)DELETE：请求服务器删除指定的页面</span><br><span class="line">        <span class="number">5</span>)HEAD：累死与GET请求，只不过返回的响应中没有具体的内容，用于获取报头</span><br><span class="line">        <span class="number">6</span>)CONNECT：把服务器当作跳板，让服务器代替客户端访问其它网页</span><br><span class="line">        <span class="number">7</span>)OPTIONS：允许客户端查看服务器的性能</span><br><span class="line">        <span class="number">8</span>)TRACE：回显服务器收到的请求，主要用于测试或诊断</span><br><span class="line"><span class="comment"># GET和POST区别：(面试重点、需重点掌握)</span></span><br><span class="line">        <span class="number">1</span>)GET请求中的参数会包含在URL里面，数据可以在URL中看到，而POST请求的URL不会包含这些数据，POST的数据都是通过表单形式传输的，包含在请求体中</span><br><span class="line">        <span class="number">2</span>)GET请求提交的数据最多只有<span class="number">1024</span>字节，而POST方式没有限制</span><br><span class="line">        <span class="number">3</span>)post请求相对安全</span><br></pre></td></tr></table></figure>

<h2 id="1、5-请求网址"><a href="#1、5-请求网址" class="headerlink" title="1、5  请求网址"></a>1、5  请求网址</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 请求网址</span></span><br><span class="line">	<span class="number">1</span>)请求的网址，即同意资源定位符URL，它是可以唯一确定我们想请求的资源</span><br></pre></td></tr></table></figure>

<h2 id="1、6-请求头"><a href="#1、6-请求头" class="headerlink" title="1、6  请求头"></a>1、6  请求头</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 请求头，用来说明服务器要使用的附加信息，重点掌握：Accept、Cookie、Referer、User-Agent</span></span><br><span class="line">        <span class="number">1</span>)Accept：请求报头域，用于指定客户端可接受哪些类型的信息</span><br><span class="line">        <span class="number">2</span>)Cookie：也常用复数形式Cookies，这是网站为了辨别用户进行会话跟踪而存储在用户本地的数据。它的主要功能是维持当前访问会话。</span><br><span class="line">        <span class="number">3</span>)Referer：此内容用来表示这个请求是从哪个页面发过来的，服务器可以拿到这一信息并做相应的处理，如做来源统计、防盗链处理等</span><br><span class="line">        <span class="number">4</span>)User-Agent：简称UA，它是一个特殊的字符串头，可以使服务器识别客户使用的操作系统及版本，浏览器及版本等信息。在做爬虫时附加上此信息，</span><br><span class="line">        			可以伪装为浏览器，如果不加，很可能会被识别出为爬虫</span><br><span class="line">        <span class="number">5</span>)x-requested-<span class="keyword">with</span>：XMLHtpRequest	<span class="comment"># 代表ajax请求</span></span><br><span class="line">        <span class="number">6</span>)Accept-Encoding：指定客户端可接受的内容编码</span><br><span class="line">        <span class="number">7</span>)Content-Type：也叫互联网媒体类型(Intemet Media Type) 或者MIME类型，在HTTP协议消息头中，它用来表示具体请求中的媒体类型信息。</span><br><span class="line">        			例如:text/html代表HTML格式，image/gif代表GIF图片，application/json代表JSON类型</span><br></pre></td></tr></table></figure>

<h2 id="1、7-请求体"><a href="#1、7-请求体" class="headerlink" title="1、7  请求体"></a>1、7  请求体</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 请求体</span></span><br><span class="line">	请求体一般承载的内容时POST请求中的表单数据，而对于GET请求，请求体则为空</span><br></pre></td></tr></table></figure>

<h2 id="1、8-响应"><a href="#1、8-响应" class="headerlink" title="1、8  响应"></a>1、8  响应</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 响应，是由服务端返回给客户端的，可以分为三部分：响应状态码(response status code)，响应头(response headers)，响应体(response body)</span></span><br></pre></td></tr></table></figure>

<h2 id="1、8、1-响应状态码"><a href="#1、8、1-响应状态码" class="headerlink" title="1、8、1  响应状态码"></a>1、8、1  响应状态码</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 响应状态码：用于哦按段请求后的响应状态，如200代表请求成功，404代表页面找不到，500代表服务器错误</span></span><br><span class="line"><span class="comment"># 常见的状态码：</span></span><br><span class="line">	<span class="number">200</span>系列：</span><br><span class="line">    	<span class="number">200</span> 成功	服务器已成功处理了请求	<span class="comment"># 重点</span></span><br><span class="line">        </span><br><span class="line">        <span class="number">300</span>系列：</span><br><span class="line">            <span class="number">301</span> 永久移动	请求的网页已永久移动到新位置，即永久重定向	<span class="comment"># 重点</span></span><br><span class="line">            <span class="number">302</span>	临时移动	请求的网页暂时跳转到其它页面，即暂时重定向	<span class="comment"># 重点</span></span><br><span class="line">        </span><br><span class="line">        <span class="number">400</span>系列：</span><br><span class="line">            <span class="number">400</span>	错误请求	服务器无法解析该请求	<span class="comment"># 重点</span></span><br><span class="line">            <span class="number">401</span>	未授权		请求没有进行身份验证或验证未通过</span><br><span class="line">            <span class="number">403</span>	禁止访问	服务器拒绝此请求	<span class="comment"># 重点</span></span><br><span class="line">            <span class="number">404</span>	未找到		服务器找不到请求的网页</span><br><span class="line">            </span><br><span class="line">        <span class="number">500</span>系列：</span><br><span class="line">            <span class="number">500</span>	服务器内部错误		服务器遇到错误，无法完成请求	<span class="comment"># 重点</span></span><br><span class="line">            <span class="number">501</span>	未实现		服务器不具备完成请求的功能</span><br><span class="line">            <span class="number">502</span>	错误网关	服务器作为网关或代理，从上游服务器收到无效响应</span><br><span class="line">            <span class="number">504</span>	网关超时	服务器作为网关或代理，但是没有及时从上游服务器收到请求</span><br><span class="line">            <span class="number">505</span>	HTTP版本不支持	服务器不支持请求中所用的HTTP协议版本</span><br><span class="line"></span><br><span class="line"><span class="comment">### (注意：状态码不能完全代表响应状态，部分网站的状态码是自定义的，一切以响应的数据为准)</span></span><br></pre></td></tr></table></figure>

<h2 id="1、8、2-响应头"><a href="#1、8、2-响应头" class="headerlink" title="1、8、2  响应头"></a>1、8、2  响应头</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 响应头：</span></span><br><span class="line">    响应头包含了服务器对请求的应答信息</span><br><span class="line">    Date：表示响应产生的时间</span><br><span class="line">    Content-Encoding：指定响应内容的编码</span><br><span class="line">    Server：包含服务器的信息，比如名称、版本号等</span><br><span class="line">    Content-Type：文档类型，指定返回的数据类型是什么，如text/html代表返回HTML文档，application/x-javascriot则表达返回JavaScript文件，</span><br><span class="line">    			image/jpeg则代表返回图片</span><br><span class="line">    Set-Cookie：设置Cookies，响应头中的Set-Cookie告诉浏览器需要将此内容放在Cookie中，下次请求携带Cookie请求</span><br><span class="line">    Expires：指定响应的过期时间，可以使代理服务器或浏览器将加载的内容更新到缓存中。如果再次访问时，就可以直接从缓存中加载，降低服务器负载，</span><br><span class="line">    		缩短加载时间</span><br></pre></td></tr></table></figure>

<h2 id="1、8、3-响应体"><a href="#1、8、3-响应体" class="headerlink" title="1、8、3  响应体"></a>1、8、3  响应体</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#  响应体</span></span><br><span class="line"><span class="comment"># 最重要的当属响应体的内容了，响应的正文数据都在响应体中。</span></span><br><span class="line">	比如请求网页时，他的响应体就是网页的HTML代码，请求一张图片时，他的相应体就是图片的二进制数据。我们做爬虫请求网页后，要解析的内容就是响应体</span><br></pre></td></tr></table></figure>

<h2 id="1、9-网页基础"><a href="#1、9-网页基础" class="headerlink" title="1、9  网页基础"></a>1、9  网页基础</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 网页的组成</span></span><br><span class="line">网页可以分为三部分：HTML、CSS、JavaScript</span><br><span class="line">        <span class="number">1</span>)HTML：全称：Hyper Text Markup Language、即超文本标记语言</span><br><span class="line">        <span class="comment"># 定义了网页的骨架</span></span><br><span class="line">        <span class="number">2</span>)CSS：全称：Cascading Style Sheets，即层叠样式表</span><br><span class="line">        <span class="comment"># 定义了网页的样式</span></span><br><span class="line">        <span class="number">3</span>)JavaScript：简称JS，是一种脚本语言</span><br><span class="line">        <span class="comment"># 定义了网页与用户的交互行为，如下载进度条，提示框，轮播图</span></span><br></pre></td></tr></table></figure>

<h2 id="2、第一次请求"><a href="#2、第一次请求" class="headerlink" title="2、第一次请求"></a>2、第一次请求</h2><h2 id="2、1-爬虫的工作流"><a href="#2、1-爬虫的工作流" class="headerlink" title="2、1  爬虫的工作流"></a>2、1  爬虫的工作流</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">确定URL，想服务器发送请求并获得响应：requests、urllib、aiohttp</span><br><span class="line">在响应中提取目标数据，即数据解析：xpath、bs4、正则、PyQuery</span><br><span class="line">数据持久化：文件，关系型数据库，非关系型数据库</span><br></pre></td></tr></table></figure>

<h2 id="2、2-第一个爬虫"><a href="#2、2-第一个爬虫" class="headerlink" title="2、2  第一个爬虫"></a>2、2  第一个爬虫</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 需求：爬取报读首页，并写入文件中，最后用浏览器打开文件查看效果</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 导包</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"></span><br><span class="line"><span class="comment"># 确定url，向服务器发送请求</span></span><br><span class="line">url = <span class="string">'https://www.baidu.com/'</span></span><br><span class="line">res = requests.get(url=rul)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 操作响应数据，获取目标数据，根据网页编码模式进行编码</span></span><br><span class="line">res.encoding = <span class="string">'utf-8'</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 将目标数据持久化到本地：写入文件</span></span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'baidu.html'</span>,<span class="string">'w'</span>,encoding = <span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.write(res.text)	<span class="comment"># res.text	代表将获取的文本</span></span><br></pre></td></tr></table></figure>

<h2 id="2、3-requests模块基本使用"><a href="#2、3-requests模块基本使用" class="headerlink" title="2、3  requests模块基本使用"></a>2、3  requests模块基本使用</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 安装requests模块</span></span><br><span class="line">pip install requests</span><br><span class="line"></span><br><span class="line"><span class="comment"># requests的请求方式</span></span><br><span class="line">	<span class="number">1</span>、get请求：</span><br><span class="line">                <span class="number">1</span>)不携带参数的get请求</span><br><span class="line">                <span class="number">2</span>)不携带参数的get请求	+  headers</span><br><span class="line">                <span class="number">3</span>)携带参数的get请求  +  headers</span><br><span class="line">            </span><br><span class="line">          <span class="number">2</span>、post请求：构建参数的post请求</span><br><span class="line">          <span class="number">3</span>、响应数据的获取与属性</span><br><span class="line">                <span class="number">3.1</span>)响应数据的获取：</span><br><span class="line">                        <span class="number">3.11</span>)res.text：文本数据</span><br><span class="line">                        <span class="number">3.12</span>)res.json()：Json数据</span><br><span class="line">                        <span class="number">3.13</span>)res.content：流</span><br><span class="line">                <span class="number">3.2</span>)响应的其它属性：</span><br><span class="line">                	<span class="number">3.21</span>)res.status_code：获取响应状态码</span><br><span class="line">                        <span class="number">3.22</span>)res.headers：响应头</span><br><span class="line">                        <span class="number">3.23</span>)res.cookie：cookie信息</span><br><span class="line">                        <span class="number">3.24</span>)res.history：响应历史</span><br></pre></td></tr></table></figure>

<h2 id="2、3、1-requests模块的get请求"><a href="#2、3、1-requests模块的get请求" class="headerlink" title="2、3、1  requests模块的get请求"></a>2、3、1  requests模块的get请求</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 不携带参数的get请求：爬取搜狗主页</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">url = <span class="string">'https://www.sogou.com/'</span></span><br><span class="line">res = requests.get(url=url)</span><br><span class="line">res.encoding = <span class="string">'utf-8'</span></span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'sogou.html'</span>,<span class="string">'w'</span>,encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.write(res.text)</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 不携带参数的get请求 + readers：爬取知乎的发现页</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'User-Agent'</span>: <span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">url = <span class="string">'https://www.zhihu.com/explore'</span></span><br><span class="line">res = requests.get(url = url,headers = headers)</span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'zhihu.html'</span>,<span class="string">'w'</span>,encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.write(res.text)</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 携带参数的get请求 + headers：知乎的发现栏中搜索Python</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">headers = &#123;</span><br><span class="line">     <span class="string">'User-Agent'</span>:<span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">url =  <span class="string">'https://www.zhihu.com/search?'</span></span><br><span class="line">params = &#123;</span><br><span class="line">    <span class="string">'type'</span> : <span class="string">'content'</span>,</span><br><span class="line">    <span class="string">'q'</span> : <span class="string">'python'</span></span><br><span class="line">&#125;</span><br><span class="line">res = requests.get(url = url , headers = headers , params = params)</span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'zhihu.html'</span> , <span class="string">'w'</span> , encoding = <span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.wirte(res.text)</span><br></pre></td></tr></table></figure>

<h2 id="2、3、2-requests模块的post请求"><a href="#2、3、2-requests模块的post请求" class="headerlink" title="2、3、2  requests模块的post请求"></a>2、3、2  requests模块的post请求</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># requests的post请求：以post方式请求：百度翻译时返回的请求信息</span></span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'User-Agent'</span>: <span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">url = <span class="string">'https://fanyi.baidu.com/sug'</span></span><br><span class="line">data = &#123;</span><br><span class="line">    <span class="string">'kw'</span> : <span class="string">'girlgriend'</span></span><br><span class="line">&#125;</span><br><span class="line">res = requests.post(url = url , headers = headers , data = data)</span><br><span class="line">print(josn.loads(res.text))</span><br></pre></td></tr></table></figure>

<h2 id="3、josn形式与流形式的响应数据示例"><a href="#3、josn形式与流形式的响应数据示例" class="headerlink" title="3、josn形式与流形式的响应数据示例"></a>3、josn形式与流形式的响应数据示例</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># json形式响应数据示例：bilibili的Python视频教程，目录列表</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">headers = &#123;</span><br><span class="line">     <span class="string">'User-Agent'</span>:<span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">url = <span class="string">'https://api.bilibili.com/x/web-interface/view?aid=14184325&amp;cid=23153678'</span></span><br><span class="line">res = requests.get(url = url , headers = headers)</span><br><span class="line">print(res)</span><br><span class="line">print(res.status_code)</span><br><span class="line">print(res.headers)</span><br><span class="line">print(<span class="string">'----------------------------------------------------'</span>)</span><br><span class="line">print(res.json())</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 流形式响应数据示例：站长素材的简历模板</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line">headers = &#123;</span><br><span class="line">     <span class="string">'User-Agent'</span>:<span class="string">'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'</span></span><br><span class="line">&#125;</span><br><span class="line">url = <span class="string">'http://fjdx.sc.chinaz.net/Files/DownLoad/jianli/201907/jianli10810.rar'</span></span><br><span class="line">res = requests.get(url = url , headers = headers)</span><br><span class="line">print(res.content)</span><br><span class="line"><span class="keyword">with</span> open(<span class="string">'jianli.rar'</span> , <span class="string">'wb'</span>) <span class="keyword">as</span> f:</span><br><span class="line">    f.write(res.content)</span><br></pre></td></tr></table></figure>






    </div>

    
    
    

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束 <i class="fa fa-paw"></i> 感谢您的阅读-------------</div>
    
</div>
      
    </div>
    
    <div>
      
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/Spider/Spider_id_16.html">网页请求</a></p>
  <p><span>文章作者:</span><a href="/" title="访问 Yu ting 的个人博客">Yu ting</a></p>
  <p><span>发布时间:</span>2020年05月29日 - 19:05</p>
  <p><span>最后更新:</span>2020年05月17日 - 15:05</p>
  <p><span>原始链接:</span><a href="/Spider/Spider_id_16.html" title="网页请求">https://tian_yu_ting.gitee.io/Spider/Spider_id_16.html</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="https://tian_yu_ting.gitee.io/Spider/Spider_id_16.html"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
    $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
    });
    });  
</script>

      
    </div>
      
  <div class="popular-posts-header">相关文章推荐</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\Spider\Spider_id_15.html" rel="bookmark">爬虫的介绍</a></div>
    </li>
  </ul>

        <div class="reward-container">
  <div>可以请我喝杯咖啡嘛</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechat.jpg" alt="Yu ting 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.jpg" alt="Yu ting 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Spider/" rel="tag">分类： Spider</a>
          </div>

        
  <div class="post-widgets">
    <div class="wp_rating">
      <div id="wpac-rating"></div>
    </div>
  </div>


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/Spider/Spider_id_15.html" rel="prev" title="爬虫的介绍">
      <i class="fa fa-chevron-left"></i> 爬虫的介绍
    </a></div>
      <div class="post-nav-item">
    <a href="/Spider/Spider_id_17.html" rel="next" title="文件的操作">
      文件的操作 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


              <!-- 此处可在文章模块中间添加东西 -->
          </div>
          <!-- 评论系统 -->
          <!--
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
-->
        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1、请求过程"><span class="nav-text">1、请求过程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、1-URL介绍"><span class="nav-text">1、1  URL介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、2-HTTP请求过程"><span class="nav-text">1、2  HTTP请求过程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、3-请求四部分"><span class="nav-text">1、3  请求四部分</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、4-请求的八种方法"><span class="nav-text">1、4  请求的八种方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、5-请求网址"><span class="nav-text">1、5  请求网址</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、6-请求头"><span class="nav-text">1、6  请求头</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、7-请求体"><span class="nav-text">1、7  请求体</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、8-响应"><span class="nav-text">1、8  响应</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、8、1-响应状态码"><span class="nav-text">1、8、1  响应状态码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、8、2-响应头"><span class="nav-text">1、8、2  响应头</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、8、3-响应体"><span class="nav-text">1、8、3  响应体</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1、9-网页基础"><span class="nav-text">1、9  网页基础</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、第一次请求"><span class="nav-text">2、第一次请求</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、1-爬虫的工作流"><span class="nav-text">2、1  爬虫的工作流</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、2-第一个爬虫"><span class="nav-text">2、2  第一个爬虫</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、3-requests模块基本使用"><span class="nav-text">2、3  requests模块基本使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、3、1-requests模块的get请求"><span class="nav-text">2、3、1  requests模块的get请求</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2、3、2-requests模块的post请求"><span class="nav-text">2、3、2  requests模块的post请求</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3、josn形式与流形式的响应数据示例"><span class="nav-text">3、josn形式与流形式的响应数据示例</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Yu ting"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">Yu ting</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">171</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">16</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">66</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yourname" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://mail.google.com/mail/u/0/#inbox" title="E-Mail → https:&#x2F;&#x2F;mail.google.com&#x2F;mail&#x2F;u&#x2F;0&#x2F;#inbox" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/u/6207787940" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;u&#x2F;6207787940" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://news.google.com/?hl=zh-HK&gl=HK&ceid=HK%253Azh-Hant" title="Google → https:&#x2F;&#x2F;news.google.com&#x2F;?hl&#x3D;zh-HK&amp;gl&#x3D;HK&amp;ceid&#x3D;HK%3Azh-Hant" rel="noopener" target="_blank"><i class="fa fa-fw fa-google"></i>Google</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://v3u.cn/" title="https:&#x2F;&#x2F;v3u.cn&#x2F;" rel="noopener" target="_blank">刘悦的技术博客</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://www.missbless.cn/" title="http:&#x2F;&#x2F;www.missbless.cn&#x2F;" rel="noopener" target="_blank">ISSAC　LOVELESS</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://www.f322.xyz/" title="https:&#x2F;&#x2F;www.f322.xyz&#x2F;" rel="noopener" target="_blank">逆の神様</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://www.wosowoso.com/" title="http:&#x2F;&#x2F;www.wosowoso.com&#x2F;" rel="noopener" target="_blank">素材网</a>
        </li>
    </ul>
  </div>

      </div>
      <div style="width:220px;text-align:center;padding-top:10px;margin-bottom:10px;border-bottom:1px dotted #000;"></div>
      <!-- 数字时钟 -->
      <!-- canvas粒子时钟 https://www.cnblogs.com/xiaohuochai/p/6368039.html
  https://www.html5tricks.com/html5-canvas-dance-time.html
 -->
<div id="">
  <canvas id="canvas" style="width:60%;">
</div>
<script>
(function(){
  var WINDOW_WIDTH = 820;
        var WINDOW_HEIGHT = 250;
        var RADIUS = 7; //球半径
        var NUMBER_GAP = 10; //数字之间的间隙
        var u=0.65; //碰撞能量损耗系数
        var context; //Canvas绘制上下文
        var balls = []; //存储彩色的小球
        const colors = ["#33B5E5","#0099CC","#AA66CC","#9933CC","#99CC00","#669900","#FFBB33","#FF8800","#FF4444","#CC0000"]; //彩色小球的颜色
        var currentNums = []; //屏幕显示的8个字符
        var digit =
                  [
                      [
                          [0,0,1,1,1,0,0],
                          [0,1,1,0,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,0,1,1,0],
                          [0,0,1,1,1,0,0]
                      ],//0
                      [
                          [0,0,0,1,1,0,0],
                          [0,1,1,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [1,1,1,1,1,1,1]
                      ],//1
                      [
                          [0,1,1,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,0,0],
                          [0,0,1,1,0,0,0],
                          [0,1,1,0,0,0,0],
                          [1,1,0,0,0,0,0],
                          [1,1,0,0,0,1,1],
                          [1,1,1,1,1,1,1]
                      ],//2
                      [
                          [1,1,1,1,1,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,0,0],
                          [0,0,1,1,1,0,0],
                          [0,0,0,0,1,1,0],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0]
                      ],//3
                      [
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,1,0],
                          [0,0,1,1,1,1,0],
                          [0,1,1,0,1,1,0],
                          [1,1,0,0,1,1,0],
                          [1,1,1,1,1,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,0,1,1,0],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,1,1]
                      ],//4
                      [
                          [1,1,1,1,1,1,1],
                          [1,1,0,0,0,0,0],
                          [1,1,0,0,0,0,0],
                          [1,1,1,1,1,1,0],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0]
                      ],//5
                      [
                          [0,0,0,0,1,1,0],
                          [0,0,1,1,0,0,0],
                          [0,1,1,0,0,0,0],
                          [1,1,0,0,0,0,0],
                          [1,1,0,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0]
                      ],//6
                      [
                          [1,1,1,1,1,1,1],
                          [1,1,0,0,0,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,0,0],
                          [0,0,0,1,1,0,0],
                          [0,0,1,1,0,0,0],
                          [0,0,1,1,0,0,0],
                          [0,0,1,1,0,0,0],
                          [0,0,1,1,0,0,0]
                      ],//7
                      [
                          [0,1,1,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,1,1,0]
                      ],//8
                      [
                          [0,1,1,1,1,1,0],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [1,1,0,0,0,1,1],
                          [0,1,1,1,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,0,1,1],
                          [0,0,0,0,1,1,0],
                          [0,0,0,1,1,0,0],
                          [0,1,1,0,0,0,0]
                      ],//9
                      [
                          [0,0,0,0],
                          [0,0,0,0],
                          [0,1,1,0],
                          [0,1,1,0],
                          [0,0,0,0],
                          [0,0,0,0],
                          [0,1,1,0],
                          [0,1,1,0],
                          [0,0,0,0],
                          [0,0,0,0]
                      ]//:
                  ];

        function drawDatetime(cxt){
            var nums = [];

            context.fillStyle="#005eac"
            var date = new Date();
            var offsetX = 70, offsetY = 30;
            var hours = date.getHours();
            var num1 = Math.floor(hours/10);
            var num2 = hours%10;
            nums.push({num: num1});
            nums.push({num: num2});
            nums.push({num: 10}); //冒号
            var minutes = date.getMinutes();
            var num1 = Math.floor(minutes/10);
            var num2 = minutes%10;
            nums.push({num: num1});
            nums.push({num: num2});
            nums.push({num: 10}); //冒号
            var seconds = date.getSeconds();
            var num1 = Math.floor(seconds/10);
            var num2 = seconds%10;
            nums.push({num: num1});
            nums.push({num: num2});

            for(var x = 0;x<nums.length;x++){
                nums[x].offsetX = offsetX;
                offsetX = drawSingleNumber(offsetX,offsetY, nums[x].num,cxt);
                //两个数字连一块，应该间隔一些距离
                if(x<nums.length-1){
                    if((nums[x].num!=10) &&(nums[x+1].num!=10)){
                        offsetX+=NUMBER_GAP;
                    }
                }
            }

            //说明这是初始化
            if(currentNums.length ==0){
                currentNums = nums;
            }else{
                //进行比较
                for(var index = 0;index<currentNums.length;index++){
                    if(currentNums[index].num!=nums[index].num){
                        //不一样时，添加彩色小球
                        addBalls(nums[index]);
                        currentNums[index].num=nums[index].num;
                    }
                }
            }
            renderBalls(cxt);
            updateBalls();

            return date;
        }

        function addBalls (item) {
            var num = item.num;
            var numMatrix = digit[num];
            for(var y = 0;y<numMatrix.length;y++){
                for(var x = 0;x<numMatrix[y].length;x++){
                    if(numMatrix[y][x]==1){
                        var ball={
                            offsetX:item.offsetX+RADIUS+RADIUS*2*x,
                            offsetY:30+RADIUS+RADIUS*2*y,
                            color:colors[Math.floor(Math.random()*colors.length)],
                            g:1.5+Math.random(),
                            vx:Math.pow(-1, Math.ceil(Math.random()*10))*4+Math.random(),
                            vy:-5
                        }
                        balls.push(ball);
                    }
                }
            }
        }

        function renderBalls(cxt){
            for(var index = 0;index<balls.length;index++){
                cxt.beginPath();
                cxt.fillStyle=balls[index].color;
                cxt.arc(balls[index].offsetX, balls[index].offsetY, RADIUS, 0, 2*Math.PI);
                cxt.fill();
            }
        }

        function updateBalls () {
            var i =0;
            for(var index = 0;index<balls.length;index++){
                var ball = balls[index];
                ball.offsetX += ball.vx;
                ball.offsetY += ball.vy;
                ball.vy+=ball.g;
                if(ball.offsetY > (WINDOW_HEIGHT-RADIUS)){
                    ball.offsetY= WINDOW_HEIGHT-RADIUS;
                    ball.vy=-ball.vy*u;
                }
                if(ball.offsetX>RADIUS&&ball.offsetX<(WINDOW_WIDTH-RADIUS)){

                    balls[i]=balls[index];
                    i++;
                }
            }
            //去除出边界的球
            for(;i<balls.length;i++){
                balls.pop();
            }
        }
        function drawSingleNumber(offsetX, offsetY, num, cxt){
            var numMatrix = digit[num];
            for(var y = 0;y<numMatrix.length;y++){
                for(var x = 0;x<numMatrix[y].length;x++){
                    if(numMatrix[y][x]==1){
                        cxt.beginPath();
                        cxt.arc(offsetX+RADIUS+RADIUS*2*x,offsetY+RADIUS+RADIUS*2*y,RADIUS,0,2*Math.PI);
                        cxt.fill();
                    }
                }
            }
            cxt.beginPath();
            offsetX += numMatrix[0].length*RADIUS*2;
            return offsetX;
        }

        var canvas = document.getElementById("canvas");
        canvas.width=WINDOW_WIDTH;
        canvas.height=WINDOW_HEIGHT;
        context = canvas.getContext("2d");

        //记录当前绘制的时刻
        var currentDate = new Date();

        setInterval(function(){
            //清空整个Canvas，重新绘制内容
            context.clearRect(0, 0, context.canvas.width, context.canvas.height);
            drawDatetime(context);
        }, 50)
})();
</script>

      <!-- 建站时间 -->
      
      
      <!-- 音乐 -->
<!--       <div>
        <audio src="/images/林俊杰 - 对的时间点.flac" autoplay="autoplay" controls="controls" loop="loop"></audio>
        
          <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=298 height=52 src="//music.163.com/outchain/player?type=2&id=569213220&auto=1&height=32"></iframe>
         
      </div> -->
    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heartbeat" style="color:red"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Yu ting</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">420k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">6:22</span>
</div>
  <div class="powered-by"><a href="https://weibo.com/u/3035313940" class="theme-link" rel="noopener" target="_blank">Only丶Nie</a>
  </div>
  <span class="post-meta-divider">|</span>
  <div class="powered-by"><a href="https://weibo.com/u/6207787940" class="theme-link" rel="noopener" target="_blank">余生有你才安好丶</a>
  </div>

        
<div class="busuanzi-count">
  <script async src="/js/busuanzi.js"></script>
  <!-- https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js -->
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>总访问人数：
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>人
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>总访问量：
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>次
      </span>
    </span>
</div>







      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="/lib/three/three.min.js"></script>


  



  <script>
  if (CONFIG.page.isPost) {
    wpac_init = window.wpac_init || [];
    wpac_init.push({
      widget: 'Rating',
      id    : 24337,
      el    : 'wpac-rating',
      color : 'fc6423'
    });
    (function() {
      if ('WIDGETPACK_LOADED' in window) return;
      WIDGETPACK_LOADED = true;
      var mc = document.createElement('script');
      mc.type = 'text/javascript';
      mc.async = true;
      mc.src = '//embed.widgetpack.com/widget.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(mc, s.nextSibling);
    })();
  }
  </script>

  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'usjRVOXqGpbFIevxocLk2MXI-gzGzoHsz',
      appKey     : 'xd98ffpeQETblJ8uuGPacjjS',
      placeholder: "请在此处填写评论",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : true,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>


  <!-- 动画效果 -->
  

    <!-- 鼠标跟随 -->
  
  <!-- 鼠标指针 -->
  <style>
    body{cursor:url(/images/正常选择.cur),move}
    a{cursor:url(/images/链接选择.cur),wait} 
  </style>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false});</script></body>
</html>
